package work20241223;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author zdl
 * @date 2024/12/23
 */
public class Demo5 {
    public static void main(String[] args) {
        new Thread("线程1:"){
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(this.getName()+"----------->"+i);
                }
            }
        }.start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName()+"------------>"+i);
                }
            }
        }, "线程2:").start();
        FutureTask<String> futureTask = new FutureTask<>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(2000);
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName()+"------------>"+i);
                }
                return "哈哈哈";
            }
        });
        new Thread(futureTask,"线程3:").start();
    }
}
